<?php
require_once 'Zend/Db.php';
require_once 'application/constant/constant.php';
require_once 'application/library/config/gcConfigRegistry.php';
//require_once 'application/library/helper/encryptionHelper.php';
require_once 'application/library/config/gcConfigAction.php';

/** 
 * gcDb
 * @author    Soochow University
 * @version   1.0
 * @exclude   作  成  日：2011/04/07
 */
class gcDb{
    
    /**
     * db
     */
    public $db;
    
    /**
     * adapter
     */
    private $adapter=sysConstant::PDO_MYSQL;
    
    /**
     * config
     */
    private $config;
    
    /**
     * __construct
     * @param   string  $p_adapter 
     * @param   array   $p_config
     */
    public function __construct($p_adapter=null, $p_config=null){
        if(!is_null($p_adapter)&& !is_null($p_config)){
            $this->adapter=$p_adapter;
            $this->config=$p_config;
        }
    }
    
    /**
     * DB打开
     * openDb
     */
    public function openDb(){
        if(is_null($this->config)){
            $this->loaderDb();
            $this->config=gcConfigRegistry::get(sysConstant::DB_NAME_EPSITE);
        }
        //$this->config["password"] = encryptionHelper::decryptByAes($this->config["password"])；
        $this->db=Zend_Db::factory($this->adapter, $this->config);
        $this->db->query("SET NAMES 'utf8'");
    }

    private function loaderDb(){
        gcConfigAction::loaderDBConfig();
    }
}
